package com.ccyang;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Random;
import java.util.stream.IntStream;
import java.util.stream.Stream;

/**
 * @author: yangjinpeng
 * @date: 2018-12-23
 * @description: 流的创建
 */
public class StreamDemo2 {

    public static void main(String[] args) {

        List<String> list = new ArrayList<>();

        // 从集合创建
        list.stream();
        list.parallelStream();

        // 从数组创建
        Arrays.stream(new int[]{1,2,3});

        // 创建数字流
        IntStream.of(1,2,3);
        IntStream range = IntStream.range(1, 5);
        System.out.println(range.sum());

        System.out.println("-----------------------");

        // 使用 Random创建一个无限流
        IntStream limit = new Random().ints().limit(6);
        limit.forEach(i -> System.out.println("Random 创建: " + i));

        System.out.println("-----------------------");
        Random random = new Random();
        Stream<Integer> limit1 = Stream.generate(() -> random.nextInt()).limit(5);
        limit1.forEach(i -> System.out.println("generate 创建：" + i));


    }


}
